﻿/*******************************************************
*类名称：WechatMemuManager
*版本号：V1.0.0.0
*作者：成俊杰
*CLR版本：4.0.30319.36264
*创建时间：2017-08-15 20:45:26
*说明：T_WechatMemu仓储类
*更新备注：
**********************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wechat.Domain;
using Wechat.Dto.Response;
using Wechat.Dto.Search;
using Wechat.Util.Paged;

namespace Wechat.Dao.Implement
{
    /// <summary>
    /// T_WechatMemu
    /// </summary>
    public class WechatMemuRepository : RepositoryBase<WechatMemu>, IWechatMemuRepository
    {
        /// <summary>
        /// 获取微信菜单分页
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public PagedList<WechatMemuResponse> GetWechatMemuPageData(WechatMemuSearch request)
        {
            PageCriteria criteria = new PageCriteria();
            if (request != null)
            {
                criteria.CurrentPage = request.PageNum == 0 ? 1 : request.PageNum;
                criteria.PageSize = request.PageSize;

                StringBuilder strWhere = new StringBuilder();
                strWhere.Append(" and wx.IsDeleted<>1");
                if (!string.IsNullOrWhiteSpace(request.WechatName))
                    strWhere.AppendFormat(" and wx.WechatName Like '%{0}%'", request.WechatName);
                if (!string.IsNullOrWhiteSpace(request.WechatType))
                    strWhere.AppendFormat(" and wx.WechatType={0}", request.WechatType);
                if (request.ParentId != -1)
                    strWhere.AppendFormat(" and wx.ParentId={0}", request.ParentId);
                criteria.Condition = strWhere.ToString();
                criteria.PrimaryKey = " wx.WechatId";
                criteria.Fields = @"  wx.WechatId
      ,wx.WechatName
      ,wx.WechatUrl
      ,wx.WechatType
      ,wx.ParentId
      ,wx.OperaterId
      ,wx.CreateTime
      ,wx.LastUpdateOperaterId
      ,wx.LastUpdateTime
      ,wx.IsEnable";
                criteria.TableName = " [T_WechatMemu] wx";
                var pageData = base.GetPageDataList<WechatMemuResponse>(criteria);
                pageData.CurrentPageItems = pageData.CurrentPageItems.Select((n, i) =>
                {
                    n.rownum = i + 1;
                    return n;
                });
                return pageData;
            }
            return null;
        }
    }
}